package com.ruoyi.project.wechatprogram.orderdescription.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wechatprogram.orderdescription.domain.WxOrderDescription;
import com.ruoyi.project.wechatprogram.orderdescription.service.IWxOrderDescriptionService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 餐品订单详情Controller
 * 
 * @author sxchen
 * @date 2020-04-21
 */
@Controller
@RequestMapping("/wechatprogram/orderdescription")
public class WxOrderDescriptionController extends BaseController
{
    private String prefix = "wechatprogram/orderdescription";

    @Autowired
    private IWxOrderDescriptionService wxOrderDescriptionService;

    @RequiresPermissions("wechatprogram:orderdescription:view")
    @GetMapping()
    public String orderdescription()
    {
        return prefix + "/orderdescription";
    }

    /**
     * 查询餐品订单详情列表
     */
    @RequiresPermissions("wechatprogram:orderdescription:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxOrderDescription wxOrderDescription)
    {
        startPage();
        List<WxOrderDescription> list = wxOrderDescriptionService.selectWxOrderDescriptionList(wxOrderDescription);
        return getDataTable(list);
    }

    /**
     * 导出餐品订单详情列表
     */
    @RequiresPermissions("wechatprogram:orderdescription:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxOrderDescription wxOrderDescription)
    {
        List<WxOrderDescription> list = wxOrderDescriptionService.selectWxOrderDescriptionList(wxOrderDescription);
        ExcelUtil<WxOrderDescription> util = new ExcelUtil<WxOrderDescription>(WxOrderDescription.class);
        return util.exportExcel(list, "orderdescription");
    }

    /**
     * 新增餐品订单详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存餐品订单详情
     */
    @RequiresPermissions("wechatprogram:orderdescription:add")
    @Log(title = "餐品订单详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxOrderDescription wxOrderDescription)
    {
        return toAjax(wxOrderDescriptionService.insertWxOrderDescription(wxOrderDescription));
    }

    /**
     * 修改餐品订单详情
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        WxOrderDescription wxOrderDescription = wxOrderDescriptionService.selectWxOrderDescriptionById(id);
        mmap.put("wxOrderDescription", wxOrderDescription);
        return prefix + "/edit";
    }

    /**
     * 修改保存餐品订单详情
     */
    @RequiresPermissions("wechatprogram:orderdescription:edit")
    @Log(title = "餐品订单详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxOrderDescription wxOrderDescription)
    {
        return toAjax(wxOrderDescriptionService.updateWxOrderDescription(wxOrderDescription));
    }

    /**
     * 删除餐品订单详情
     */
    @RequiresPermissions("wechatprogram:orderdescription:remove")
    @Log(title = "餐品订单详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxOrderDescriptionService.deleteWxOrderDescriptionByIds(ids));
    }
}
